/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// TGUI - Texus's Graphical User Interface
// Copyright (C) 2012 Bruno Van de Velde (VDV_B@hotmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
//    you must not claim that you wrote the original software.
//    If you use this software in a product, an acknowledgment
//    in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
//    and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


#ifndef _TGUI_WINDOW_INCLUDED_
#define _TGUI_WINDOW_INCLUDED_

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

namespace tgui
{
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    struct TGUI_API Window : public Group, sf::RenderWindow
    {
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Default constructor
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        Window();


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// The constructor is just the same as the one from the sf::RenderWindow.
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        Window(sf::VideoMode mode, const std::string& title, sf::Uint32 style = sf::Style::Default, const sf::ContextSettings& settings = sf::ContextSettings());

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// The constructor is just the same as the one from the sf::RenderWindow.
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        explicit Window(sf::WindowHandle handle, const sf::ContextSettings& settings = sf::ContextSettings());


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Destructor
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ~Window();


        //////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Passes the event to the objects.
        /// You should call this function in your event loop.
        //////////////////////////////////////////////////////////////////////////////////////////////////////
        void handleEvent(sf::Event& event);


        //////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Loads a form from a file. The objects will be loaded inside the window.
        /// Note that even when this function fails, some objects might have been loaded already.
        ///
        /// return: True on success.
        ///         False when the file couldn't be opened or when the file constains a mistake.
        //////////////////////////////////////////////////////////////////////////////////////////////////////
        bool loadObjectsFromFile(const std::string pathname);


        //////////////////////////////////////////////////////////////////////////////////////////////////////
        /// Draws all the objects that were added to the window.
        /// You can optionally pass some global render states (untested).
        //////////////////////////////////////////////////////////////////////////////////////////////////////
        void drawGUI(const sf::RenderStates& states = sf::RenderStates::Default);


        //////////////////////////////////////////////////////////////////////////////////////////////////////
        /// This function works just like the PollEvent function from sfml.
        /// The window stores the callback of all the objects.
        /// This function will return the next callback and then remove it from the queue.
        /// Note that more than one callbacks may be present in the queue, thus you should always call this
        /// function in a loop to make sure that you process every callback.
        ///
        /// return: True when there is another callback. The callback parameter will be filled with information.
        ///         False when there was no callback. The callback parameter may not be used.
        //////////////////////////////////////////////////////////////////////////////////////////////////////
        bool getCallback(Callback& callback);


        //////////////////////////////////////////////////////////////////////////////////////////////////////
        /// TGUI uses this function internally to handle object callbacks. When you allow an object to pass
        /// callbacks then this function is called to tell the window about the callback.
        /// You can use this function to fake an object callback.
        //////////////////////////////////////////////////////////////////////////////////////////////////////
        void addCallback(Callback& callback);


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    private:

        // This will store all object callbacks until you pop them with getCallback
        std::queue<Callback> m_Callback;

        // The internal clock which is used for animation of objects
        sf::Clock m_Clock;

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    };

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#endif //_TGUI_WINDOW_INCLUDED_
